********************************************************************
**** Table A9: PRODUCTIVITY HETEROGENEITY BY HOUSE QUALITY 	****
********************************************************************

use "$dir/Data/analysis_main.dta", clear


	cap drop *_hiw
	foreach y of varlist cash_postpay {
		gen `y'_hiw = richhouse*`y'
		gen `y'_miss_hiw = richhouse_miss*`y'
	}		

	eststo clear

	foreach x of varlist n_productivity{

		eststo: reghdfe `x' cash_postpay cash_announce cash_postpay_hiw cash_postpay_miss_hiw richhouse richhouse_miss blhrprod blhrprodsq blhrprod_miss bs_labor_30_miss future_fin_worry_miss i.pd if pd>0, vce(cl pid) absorb(roundgroup)
		qui lincom cash_postpay + cash_postpay_hiw
		qui estadd scalar coef1 = r(estimate)
		qui estadd scalar se1 = r(se)					
		qui estadd scalar pval1 = 2*ttail(r(df),abs(r(estimate)/r(se)))

	}
	
	foreach x of varlist att_ind hiatt_ind {

		eststo: reghdfe `x' cash_postpay cash_announce cash_postpay_hiw cash_postpay_miss_hiw richhouse richhouse_miss blatt blatt_miss blhrprod_miss read_odiya_nm read_odiya_miss bs_labor_30_miss future_fin_worry_miss i.pd if pd>0, vce(cl pid) absorb(roundgroup)
		qui lincom cash_postpay + cash_postpay_hiw
		qui estadd scalar coef1 = r(estimate)
		qui estadd scalar se1 = r(se)					
		qui estadd scalar pval1 = 2*ttail(r(df),abs(r(estimate)/r(se)))

	}

	label var cash_postpay "Cash $\times$ Post-pay" 
	label var cash_postpay_hiw "Cash $\times$ Post-pay $\times$ House quality" 

	#delimit ;
	local tablerow cash_postpay cash_postpay_hiw;

	esttab using "$oa/$t/Table_A9.tex", 
		b(3) se booktabs star(* .1 ** .05 *** .01) nonotes nomtitles  
		replace label style(tex) gaps keep(`tablerow') order(`tablerow') 
		stats(coef1 se1 pval1 N, labels( "Coef: cash effect + interaction" "SE: cash effect + interaction" "P-val: cash effect + interaction" "N: worker-hours") fmt(%9.3fc %9.3fc %9.3fc %9.0fc)) 
		prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \begin{tabular}                 {@{\extracolsep{4pt}}l*{10}{>{\centering\arraybackslash}m{3.5cm}}@{}}                  \toprule 
		&\multicolumn{1}{c}{Hourly Production}  &\multicolumn{1}{c}{Attentiveness Index}  &\multicolumn{1}{c}{High Attentiveness}   \\") ;
	#delimit cr	



